home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / HENSA / MATHS / PLPLOT / PLPLOT.ZIP / examples / tk / tk02 < prev    next >
Encoding:
Text File  |  1994-07-24  |  5.4 KB  |  224 lines

  1. #!xtk02 -f
  2. # Geoffrey Furnish                     -*-tcl-*-
  3. # 11 April 1994
  4. #
  5. # @> A script for using Tk to control xtk01, using the PLplot itcl interface.
  6. #
  7. # $Id: tk02,v 1.9 1994/07/24 07:42:58 mjl Exp $
  8. #
  9. # $Log: tk02,v $
  10. # Revision 1.9  1994/07/24  07:42:58  mjl
  11. # Eliminated "destroy ." in favor of "exit".
  12. #
  13. # Revision 1.8  1994/07/01  20:44:00  mjl
  14. # Modified to use startup proc plstdwin when configuring main window.
  15. #
  16. # Revision 1.7  1994/06/30  05:46:20  furnish
  17. # Another plot command in tk02 which invokes a private tclMatrix
  18. # extension for demo purposes.  xtk02.c adds a new tclMatrix subcommand
  19. # "stuff", and tk02 exercises it.  Dumb, but shows how it all works.
  20. #
  21. # Revision 1.6  1994/06/17  21:23:11  mjl
  22. # Removed option database settings since they were the same as those set
  23. # in the pldefaults proc.
  24. #
  25. # Revision 1.5  1994/06/16  21:56:32  mjl
  26. # Changed to new matrix declaration syntax.  Locally declared matrices go
  27. # away automatically when the proc exits.  It really works!
  28. #
  29. # Revision 1.4  1994/06/16  19:29:31  mjl
  30. # Changes to use new plframe/matrix API for functions that require array
  31. # arguments.
  32. #
  33. # Revision 1.3  1994/06/10  20:48:34  furnish
  34. # Do a lot more from Tcl.  Still needs work, but waiting on the API
  35. # mirroring to catch up.
  36. #
  37. # Revision 1.2  1994/06/09  20:29:22  mjl
  38. # Changed to new improved megawidget instantiation method.
  39. #
  40. # Revision 1.1  1994/05/09  18:01:36  furnish
  41. # A new Tk demo, combining [incr Tcl] mega widget and the PLplot Tcl
  42. # extensions.  Much more along these lines should be done.
  43. #
  44. ###############################################################################
  45.  
  46. wm title . "x01c -- TK version"
  47. plstdwin .
  48.  
  49. ###############################################################################
  50. # Set up the menubar and message widgets.
  51.  
  52. frame .menu -relief raised -borderwidth 3
  53.  
  54. button .menu.one -text "One" -command "myplot1"
  55. pack append .menu .menu.one {left expand fill}
  56.  
  57. button .menu.two -text "Two" -command "myplot 2"
  58. pack append .menu .menu.two {left expand fill}
  59.  
  60. button .menu.three -text "Three" -command "plot2"
  61. pack append .menu .menu.three {left expand fill}
  62.  
  63. button .menu.four -text "Four" -command "myplot 4"
  64. pack append .menu .menu.four {left expand fill}
  65.  
  66. button .menu.five -text "Five" -command "gumbyplot"
  67. pack append .menu .menu.five {left expand fill}
  68.  
  69. button .menu.six -text "Six" -command "snoopy"
  70. pack .menu.six -side left -expand 1 -fill x
  71.  
  72. button .menu.exit -text "Exit" -command "quit 0"
  73. pack append .menu .menu.exit {right expand fill}
  74.  
  75. message .msg \
  76.     -font -Adobe-helvetica-medium-r-normal--*-240* -aspect 200 \
  77.      -width 500 -borderwidth 1 \
  78.     -text "TK02: Demo \[incr Tcl\] interface to PLplot"
  79.  
  80. PLXWin .plw -name foo
  81.  
  82. pack append . .menu {top fillx} \
  83.     .msg {top padx 5 pady 5 fill} \
  84.     .plw {bottom expand fill}
  85.  
  86. update
  87.  
  88. tk_menuBar .menu .menu.one .menu.two .menu.three .menu.four .menu.exit
  89.  
  90. ###############################################################################
  91. # Definitions of procedures used in this script.
  92.  
  93. proc myplot1 {} {
  94.     global xscale yscale xoff yoff
  95.  
  96.     set xscale 6
  97.     set yscale 1
  98.     set xoff 0
  99.     set yoff 0
  100.  
  101.     plot1
  102. }
  103.  
  104. # This is supposed to work just like the plot1() in x01c.c/xtk02.c
  105.  
  106. proc plot1 {} {
  107.     global xscale yscale xoff yoff
  108.  
  109.     matrix x1 float 10
  110.     matrix y1 float 10
  111.  
  112.     for {set i 2; set n1 0} {$i < 60} {incr i 10; incr n1} {
  113.     set x [expr $xoff + $xscale * ($i + 1) / 60]
  114.     $x1 $n1 = $x
  115.     $y1 $n1 = [expr $yoff + $yscale * pow($x,2)]
  116.     }
  117.  
  118.     set n2 60
  119.     matrix x2 float $n2
  120.     matrix y2 float $n2
  121.  
  122.     for {set i 0} {$i < $n2} {incr i} {
  123.     set x [expr $xoff + $xscale * ($i + 1) / $n2]
  124.     $x2 $i = $x
  125.     $y2 $i = [expr $yoff + $yscale * pow($x,2)]
  126.     }
  127.  
  128.     set xmax [$x2 [expr $n2-1]]
  129.     set ymax [$y2 [expr $n2-1]]
  130.  
  131.     .plw plcol 1
  132.     .plw plenv $xoff $xmax $yoff $ymax 0 0
  133.     .plw plcol 6
  134.     .plw pllab "(x)" "(y)" "#frPLPLOT Example 1 - y=x#u2"
  135.  
  136.     # plot the data points
  137.  
  138.     .plw plcol 9
  139.     .plw plpoin $n1 $x1 $y1 9
  140.  
  141.     # plot the data points
  142.  
  143.     .plw plcol 4
  144.     .plw plline $n2 $x2 $y2
  145. }
  146.  
  147. # This is supposed to work just like the plot2() in x01c.c/xtk02.c
  148.  
  149. proc plot2 {} {
  150.     .plw plcol 1
  151.     .plw plenv -2 10 -.4 1.2 0 1
  152.     .plw plcol 2
  153.     .plw pllab "(x)" "sin(x)/x" "#frPLPLOT Example 1 - Sinc Function"
  154.  
  155.     # Fill up the array
  156.  
  157.     matrix x1 float 101
  158.     matrix y1 float 101
  159.  
  160.     for {set i 0} {$i < 101} {incr i} {
  161.     set x [expr ($i - 19.)/6.]
  162.     $x1 $i = $x
  163.     $y1 $i = 1
  164.     if {$x != 0} { $y1 $i = [expr sin($x)/$x] }
  165.     }
  166.  
  167.     .plw plcol 3
  168.     .plw plline 101 $x1 $y1
  169. }
  170.  
  171. proc gumbyplot {} {
  172.     .plw plcol 1
  173.     .plw plenv 0 1 0 1 0 0
  174.     .plw plcol 6
  175.     .plw pllab "(x)" "(y)" "#frPLplot Example 1 - y=1-2x+2x#u2"
  176.  
  177.     matrix x1 float 101
  178.     matrix y1 float 101
  179.  
  180.     for {set i 0} {$i < 101} {incr i} {
  181.     set x [expr $i * .01]
  182.     $x1 $i = $x
  183.     $y1 $i = [expr 1 - 2 * $x + 2 * $x * $x]
  184.     }
  185.  
  186.     .plw plline 101 $x1 $y1
  187. }
  188.  
  189. # This proc shows off the use of a matrix extension subcommand.
  190.  
  191. proc snoopy {} {
  192.     puts "Inside snoopy"
  193.  
  194.     matrix x float 101
  195.     matrix y float 101
  196.  
  197.     for {set i 0} {$i < 101} {incr i} {
  198.     set xx [expr $i * .01]
  199.     $x $i = $xx
  200.     }
  201.  
  202.     $y stuff
  203.  
  204.     .plw plcol 1
  205.     .plw plenv 0 1 0 1 0 0
  206.     .plw plcol 6
  207.     .plw pllab "(x)" "(y)" "#frDemo of Matrix extension subcommand"
  208.     .plw plline 101 $x $y
  209. }
  210.  
  211. # Punch eject and hold onto your seat !!!
  212.  
  213. proc quit a {
  214.     exit
  215. }
  216.  
  217. # Utility routine.
  218.  
  219. proc dpos w {
  220.     wm geometry $w +300+300
  221. }
  222.  
  223. ###############################################################################
  224.